package com.lufei.dh.ShoppingCart.Adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lufei.dh.R;
import com.lufei.dh.ShoppingCart.Bean.Bean_Item;
import com.lufei.dh.ShoppingCart.CardImp;
import com.lufei.dh.ShoppingCart.Card_Activity;

import java.util.List;

/**
 * Created by Administrator on 2018/3/24 0024.
 */

public class Adapter_Card extends BaseQuickAdapter<Bean_Item, BaseViewHolder> {
    Context mContext;
    private Button mButton;
    boolean xc = false;

    public Adapter_Card(@Nullable List<Bean_Item> data, Context context) {
        super(R.layout.card_item, data);
        mContext = context;
    }

    @Override
    protected void convert(final BaseViewHolder helper, Bean_Item item) {
        helper.setText(R.id.tv_item_info, item.getName());
        helper.setText(R.id.tv_item_price, String.valueOf(item.getMoney()));
        helper.setText(R.id.tv_item_count, String.valueOf(item.getCount()));
        helper.addOnClickListener(R.id.cb_item_check);
        CheckBox view = helper.getView(R.id.cb_item_check);
        if (item.isSelected()){
            view.setChecked(true);

        }else {
            view.setChecked(false);
        }
        Button button = helper.getView(R.id.bt_item_delete);

        helper.addOnClickListener(R.id.bt_item_delete);
        if (xc) {
            button.setVisibility(View.VISIBLE);
        } else {
            button.setVisibility(View.GONE);
        }
        addOrSubtract(R.id.bt_item_add, R.id.bt_item_subtract, R.id.tv_item_count, helper);
    }

    public void setmButton(boolean x) {
        xc = x;

        notifyDataSetChanged();
    }

    /**
     * 加减的处理
     *
     * @param add
     * @param subtract
     */
    private void addOrSubtract(int add, int subtract, int tv_item_count, final BaseViewHolder helper) {
//        Button addx = helper.getView(add);
//        Button subtractx = helper.getView(subtract);
//        TextView count = helper.getView(tv_item_count);
        helper.addOnClickListener(add);
        helper.addOnClickListener(subtract);
        helper.addOnClickListener(tv_item_count);
    }
}
